package com.hdaccp.shuiguoD.Test;

import com.hdaccp.shuiguoD.dao.*;
import com.hdaccp.shuiguoD.entity.*;
import com.hdaccp.shuiguoD.pogo.PermissionBean;
import com.hdaccp.shuiguoD.pogo.StateBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Test {

    private static ApplicationContext applicationContext;
    private static RoleDao roleDao;
    private static PermissionDao permissionDao;
    private static RolePermissionDao rolePermissionDao;
    private static userDao userDao;
    private static UserRoleDao userRoleDao;
    private static ShangpinDao shangpinDao;

    static {
        applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        roleDao = (RoleDao) applicationContext.getBean("roleDao");
        permissionDao = (PermissionDao) applicationContext.getBean("permissionDao");
        rolePermissionDao = (RolePermissionDao) applicationContext.getBean("rolePermissionDao");
        userDao = (userDao) applicationContext.getBean("userDao");
        userRoleDao = (UserRoleDao) applicationContext.getBean("userRoleDao");
        shangpinDao = (ShangpinDao) applicationContext.getBean("shangpinDao");
    }

    /**
     * 测试 查询出所有角色
     */


    public static  void testQueryRole(){
        List<Role> list = roleDao.query("",3,0) ;
        for(Role role:list){
            System.out.println(role.getRid() + "--" + role.getRname());
        }
    }



   /* public static  void testPermissionQuery(){
        List<PermissionBean> list =  permissionDao.query() ;
        for (PermissionBean p:list){
            System.out.println(p.getPid() + "--" + p.getText());
        }
    }*/

   public static void testRolePermission(){
       List<Permission> listAll = permissionDao.queryAll();

       List<Permission> listPermission = rolePermissionDao.queryByRoleId(3);

       for (Permission permission : listAll){
            StateBean stateBean = new StateBean();
            for (Permission permission1 : listPermission){
                if (permission.getPid() == permission1.getPid()){
                    stateBean.setChecked(true);
                }
            }
            //permission.setStateBean(stateBean);
       }

       for (Permission p : listAll){
          // System.out.println(p.getPname()+"---"+p.getStateBean().isChecked());
       }
   }


    public static  void testPermissionQueryByParentId(){
        List<PermissionBean> list =  permissionDao.query(0) ;
        for (PermissionBean p:list){
            System.out.println(p.getPid() + "--" + p.getText());
        }
    }



    public static void testlogin(){
        User user = userDao.login("admin","123456");
        System.out.println(user.getUid()+"--"+user.getUname());
    }

    public static void testGetRole(){
        UserRole userRole = userRoleDao.getRoleByUserId(3);
        System.out.println(userRole.getRid());
    }

   /* public static void testGetPermissionByRoleId(){
       List<Long> list = rolePermissionDao.getPermissionByRoleId(3);
       for (long id : list){
           System.out.println(id);
       }



    }*/

   /* public static void testGetPermissionByList(){
        List<Long> list = rolePermissionDao.getPermissionByRoleId(3);
        List<Permission> list1 = permissionDao.queryByPermissionIds(list);
        for (Permission permission : list1){
            System.out.println(permission.getPid()+"--"+permission.getPname()+"--"+permission.getParentid());
            for (Permission p : list1){
                if (p.getParentid() == permission.getParentid()){
                    System.out.println("\t"+permission.getPid()+"--"+permission.getPname()+"--"+permission.getParentid());
                }
            }
        }
    }
*/
   public static void  test(){
       Shangpin a =new Shangpin();
       a.setSname("11");
       a.setLid(1);
       a.setSguige("11");
       a.setSjiage(1);
       a.setSguige("11");
       a.setDid(1);
       a.setSkucun(1);
       a.setCid(1);
       a.setTime("2018-11-11");
       a.setDqtime("2018-11-11");
       shangpinDao.add(a);
   }

    public static void main (String[]args){
        test();
   }

    }

